import { LOGIN, USERINFO, GET_CHANNEL, GET_ARTICLE } from '@/store/actionTypes'
import { getToken } from '@/utils/storage'

const init = {
  token: getToken() || '',
  userInfo: {},
  channels: [],
  article: {}
}
export const login = (state = init, action) => {
  const { type, payload } = action
  switch (type) {
    case LOGIN:
      return { ...state, token: payload }
    case USERINFO:
      return { ...state, userInfo: payload }
    case 'OUT':
      return { ...state, token: '', userInfo: {} }
    case GET_CHANNEL:
      return { ...state, channels: payload }
    case GET_ARTICLE:
      return { ...state, article: payload }
    default:
      return state
  }
}
